/**
 * Created by Zzhk on 2017/7/1.
 */
//通用模板JS
$(function () {
    var fn = ABUS.Fn;

    $(".take_photo").on("touchend", function () {
        fn.wxPhoto({
            success: function (localIds, serverId) {
                if (localIds.length > 0) {
                    var img = '<img class="big_pic" data-serverId="'+ serverId +'" src="' + localIds[0] + '"/>';
                    img = $(img);
                    img.css({
                        display: "inline-block",
                        width: "auto",
                        height: "100%"
                    });
                    var $el = $(".take_photo");
                    $el.css({
                        "text-align":"center"
                    }).find("img").remove().end().append(img);

                }
            }
        });
    });
    $('.photo_next').on("touchend", function () {
        if ($(".big_pic").length > 0) {
            fn.confirm({
                onSubmit:function () {
                    fn.get({
                        url: "/leader/order/acceptOrder",
                        data: {
                            orderId: __param__.orderId,
                            mediaId:$(".big_pic").attr("data-serverId")
                        },
                        success: function (data) {
                            if (data.result === 1) {
                                fn.page_goto({
                                    url:"./zuzhang_shouye.html"
                                });
                                fn.closeModal();
                            }else{
                                fn.alert({
                                    type:"error",
                                    title:data.message
                                })
                            }
                        },
                        error:function (XMLHttpRequest, textStatus, errorThrown)  {
                            fn.alert({
                                type:"error",
                                title:JSON.stringify(XMLHttpRequest)
                            })
                        }
                    });
                },
                onCancel:function () {
                    fn.closeModal();
                }
            })
        } else {
            fn.alert({
                type:"error",
                title:"请上传图片"
            })
        }
    })

});